<?php

class vmw_Page
{
    protected $pageTitle;
    protected $pageHeader;
    protected $cssLinks;
    protected $scriptLinks;
    protected $backButton;


    public function __construct($title)
    {
        $this->SetPageTitle($title);
        $this->cssLinks = array();
        $this->scriptLinks = array();
        $this->backButton = true;

        $this->cssLinks[] = 'http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css';
        $this->cssLinks[] = 'style.css';
        $this->scriptLinks[] = 'http://code.jquery.com/jquery-1.7.1.min.js';
        $this->scriptLinks[] = 'http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js';
    }


    public function GetHTML()
    {
        $content =  $this->GetHTMLHeader();
        $content .= $this->GetHTMLBody();
        $content .= $this->GetHTMLFooter();

        return $content;
    }


    protected function GetHTMLHeader()
    {
        $content =  '<!DOCTYPE html>' . "\r\n";
        $content .= '<html>' . "\r\n";
        $content .= '<head>' . "\r\n";
        $content .= '  <title>' . $this->pageTitle . '</title>' . "\r\n";
        $content .= '  <meta name="viewport" content="width=device-width, initial-scale=1">' . "\r\n";
        $content .= '  <meta name="format-detection" content="telephone=no">' . "\r\n";
        foreach ($this->cssLinks as $k => $v)
        {
            $content .= '  <link rel="stylesheet" href="' . $v . '" />' . "\r\n";
        }
        foreach ($this->scriptLinks as $k => $v)
        {
            $content .= '  <script src="' . $v . '"></script>' . "\r\n";
        }
        $content .= '</head>' . "\r\n";

        return $content;
    }


    protected function GetHTMLBody()
    {
        $content =  "<body>\r\n";
        $content .= $this->GetJQHeader();
        $content .= $this->GetJQBody();
        $content .= $this->GetJQFooter();
        $content .= "</body>\r\n";

        return $content;
    }


    protected function GetHTMLFooter()
    {
        $content = "</html>";

        return $content;
    }


    protected function GetJQHeader()
    {
        $back = ($this->backButton === true ? ' data-add-back-btn="true"' : '');

        $content =  '  <div data-role="page"' . $back . '>' . "\r\n";
        $content .= '    <div data-role="header">' . "\r\n";
        $content .= '      <h1>' . $this->pageHeader . '</h1>' . "\r\n";
        $content .= '    </div>' . "\r\n";

        return $content;
    }


    protected function GetJQBody()
    {
        $content = '';

        return $content;
    }


    protected function GetJQFooter()
    {
        $content = '  </div>' . "\r\n";

        return $content;
    }


    public function ProcessRequest()
    {
        echo $this->GetHTML();
    }


    public function SetPageTitle($value)
    {
        $this->pageTitle = htmlspecialchars($value);
        $this->pageHeader = htmlspecialchars($value);
    }
}

?>
